﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;
using System.Text.RegularExpressions;

namespace ThuVien
{
    public partial class frmTimKiemNV : DevComponents.DotNetBar.Office2007RibbonForm 
    {
        NhanVienBUS NV_BUS = new NhanVienBUS();
        public frmTimKiemNV()
        {
            InitializeComponent();
        }
        
        private void frmTimKiemNV_Load(object sender, EventArgs e)
        {
            NV_BUS.khoitao_KN();
           
           
        }

        private void labelX1_Click(object sender, EventArgs e)
        {

        }

        private void dataGridViewX1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void cbxMaNV_Click(object sender, EventArgs e)
        {

            
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {
          
            
           

        }

        private void cbxMaNV_MouseClick(object sender, MouseEventArgs e)
        {
            if (cbxMaNV.Checked == false )
            {
                txtmaNV.Enabled = true;

            }
            else
            {
                txtmaNV.Enabled = false;
                txtmaNV.Clear();
            }
            
        }

        private void cbxhoten_MouseClick(object sender, MouseEventArgs e)
        {
            if (cbxhoten.Checked == false )
            {
                txtTenNv.Enabled = true;
            }
            else
            {
                txtTenNv.Enabled = false;
                txtTenNv.Clear();
            }
        }

        private void cbxNamSinh_MouseClick(object sender, MouseEventArgs e)
        {
            if (cbxNamSinh.Checked == false )
            {
                txtTuNam.Enabled = true;
                txtdenNam .Enabled = true;
                btnTimKiem.Enabled = true;
            }
            else
            {
                txtTuNam.Enabled = false;
                txtTuNam.Enabled = false;
                txtTuNam.Clear();
                txtdenNam.Clear();
            }

        }

        private void cbxMaNV_CheckedChanged(object sender, EventArgs e)
        {

        }
        public bool IsNumber(string pText)
        {
            Regex regex = new Regex(@"^[-+]?[0-9]*\.?[0-9]+$");
            return regex.IsMatch(pText);
        }
        private void cbxNamSinh_CheckedChanged(object sender, EventArgs e)
        {
            
           
        }

        private void txtmaNV_TextChanged(object sender, EventArgs e)
        {
            NV_BUS.khoitao_KN();
            DataSet ds = new DataSet();
            ds= NV_BUS.TimKiem_MaNV(txtmaNV.Text);
            dataGridViewX1.DataSource = ds.Tables[0];
            frmTimKiemNV_Load(sender, e);

         }

        private void txtTenNv_TextChanged(object sender, EventArgs e)
        {
            NV_BUS.khoitao_KN();
            DataSet ds = new DataSet();
            ds = NV_BUS.TimKiem_theotenNV(txtTenNv.Text);
            dataGridViewX1.DataSource = ds.Tables[0];
            frmTimKiemNV_Load(sender, e);
        }

        private void txtTuNam_TextChanged(object sender, EventArgs e)
        {
            if (IsNumber(txtTuNam.Text))
            {
                //int tu = Convert.ToInt32(txtTuNam.Text);
                //int den = Convert.ToInt32(txtdenNam.Text);
              
            }
            else
            {
                MessageBox.Show("Bạn Phải Nhập số");
            }
        }

        private void txtdenNam_TextChanged(object sender, EventArgs e)
        {
            if (IsNumber(txtdenNam.Text))
            {
               
            }
            else
            {
                MessageBox.Show("Bạn Phải Nhập số");
            }
        }

        private void btnTimKiem_Click(object sender, EventArgs e)
        {
           
            //bool kt_tu;
            //bool ktden;
            //kt_tu=IsNumber(txtTuNam.Text)
            if (IsNumber(txtTuNam.Text) && IsNumber(txtdenNam.Text))
            {
                //int tu = Convert.ToInt32(txtTuNam.Text);
                //int den = Convert.ToInt32(txtdenNam.Text);
                NV_BUS.khoitao_KN();
                DataSet ds = new DataSet();
                ds = NV_BUS.TimKiem_TheoNamSinh(Convert.ToInt32(txtTuNam.Text), Convert.ToInt32(txtdenNam .Text));
                dataGridViewX1.DataSource = ds.Tables[0];
                frmTimKiemNV_Load(sender, e);
            }
            else
            {
                MessageBox.Show("Bạn Phải Nhập số");
            }
        }

        private void buttonX2_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn Muốn Thoát Khỏi màn hình Tra Cứu", "THOÁT", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
            {
                this.Close();
                frmNhanVien f = new frmNhanVien();
                f.Show();
            }
        }

        

    }
}
